package com.zd.web.servlet;

import java.io.IOException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zd.service.impl.adminUserSelectServiceImpl;
import com.zd.entity.PageBean;
import com.zd.entity.User;
import com.zd.service.*;
/**
 * Servlet implementation class adminSelectUserServlet
 */
@WebServlet("/adminSelectUserServlet")
public class adminSelectUserServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	adminUserSelectService select=new adminUserSelectServiceImpl();
   
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");

		System.out.println("进入");
		//分页一波
		int aPageNum=5;
		String num=request.getParameter("nowPage");
		int nowPage=Integer.parseInt(num==null?"1":num);

		PageBean<User> pageBean=select.selectUser(aPageNum,nowPage);
		System.out.println(pageBean);
		request.setAttribute("pageBean", pageBean);
		request.getRequestDispatcher("user.jsp").forward(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		System.out.println("进入修改");
		User user=new User();
		int userId=Integer.parseInt(request.getParameter("userId"));
		String userNickName=request.getParameter("userNickName");
		String userPass=request.getParameter("userPass");
		String userPhone=request.getParameter("userPhone");
//		String risgterTime1=request.getParameter("risgterTime");	
//		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
//	    Date risgterTime = LocalDate.parse(risgterTime1, formatter);
		int vip=Integer.parseInt(request.getParameter("vip"));
		user.setUserId(userId);
		user.setUserNickName(userNickName);
		user.setUserPass(userPass);
		user.setUserPhone(userPhone);
		user.setVip(vip);
//		user.setRisgterTime(risgterTime);
		int num=select.updateUser(user);
		doGet(request,response);
	}

}
